﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace StringMax
{

    class Program
    {

        private static string FindMaxChar(string value)
        {
            //计算每个字符的数量并存入hashTable. key:字符名，value:字符数目
            Hashtable ht = new Hashtable();

            for (int i = 0; i < value.Length; i++)
            {
                if (!ht.ContainsKey(value.Substring(i, 1)))
                {
                    ht.Add(value.Substring(i, 1), getcount(value, value.Substring(i, 1)));
                }
            }

            int temp;

            string maxStr = string.Empty;

            List<int> lt = new List<int>();

            foreach (System.Collections.DictionaryEntry objDE in ht)
            {
                lt.Add(Convert.ToInt32(objDE.Value));
            }

            //排序
            for (int i = 0; i < lt.Count - 1; i++)
            {
                if (lt[i] > lt[i + 1])
                {
                    temp = lt[i + 1];
                    lt[i + 1] = lt[i];
                    lt[i] = temp;
                }
            }

            //取最大值
            foreach (System.Collections.DictionaryEntry objDE in ht)
            {
                if (objDE.Value.ToString() == lt[lt.Count - 1].ToString())
                {
                    maxStr = objDE.Key.ToString();
                }

            }

            return maxStr;
        }


        private static int getcount(string orignal, string strTarget)
        {

            int count = 0;

            for (int i = 0; (i = orignal.IndexOf(strTarget, i)) >= 0; i++)
            {
                count++;
            }

            return count;

        }

    }
}
